package com.lite.api.controller.publics.retailer;


import com.lite.business.convert.retailer.RetailerConvert;
import com.lite.business.entity.retailer.Retailer;
import com.lite.business.entity.retailer.RetailerQueryWrapper;
import com.lite.business.exception.BusinessException;
import com.lite.business.service.retailer.RetailerService;
import com.lite.common.dto.ResultResponse;
import com.lite.common.utils.ResultResponseUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author stranger
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/retailer")
public class RetailerController {
    @Autowired
    RetailerService retailerService;

    @Autowired
    RetailerConvert retailerConvert;


    /**
     * 获取一个零售商的信息
     *
     * @param retailerId 零售商ID
     * @return 零售商对象
     * @throws BusinessException 业务异常
     */
    @GetMapping("/getRetailerById")
    public ResultResponse<Retailer> getRetailerById(@RequestParam @NotNull Integer retailerId) throws BusinessException {
        return ResultResponseUtils.success(retailerService.getRetailerById(retailerId), "获取零售商信息成功");
    }

    /**
     * 分页获取零售商列表信息
     *
     * @param page                 页数
     * @param size                 容量
     * @param retailerQueryWrapper 条件查询包装器
     * @return 零售商信息列表
     * @throws BusinessException 业务异常
     */
    @PostMapping("/listRetailerByPage")
    public ResultResponse<List<Retailer>> listRetailerByPage(
            @RequestParam @NotNull Integer page,
            @RequestParam @NotNull Integer size,
            @RequestParam @NotNull RetailerQueryWrapper retailerQueryWrapper) throws BusinessException {
        return ResultResponseUtils.success(retailerService.listRetailerByPage(page, size, retailerQueryWrapper), "获取零售商信息列表成功");
    }

    /**
     * 更新零售商信息
     *
     * @param retailerId  零售商ID
     * @param newRetailer 新的零售商信息对象
     * @return 是否更新成功
     * @throws BusinessException 业务异常
     */
    @PostMapping("/updateRetailerInfo")
    public ResultResponse<Boolean> updateRetailerInfo(
            @RequestParam @NotNull Integer retailerId,
            @RequestParam @NotNull Retailer newRetailer) throws BusinessException {
        return ResultResponseUtils.success(retailerService.updateRetailerInfo(retailerId, newRetailer), "更新零售商信息成功");
    }

    /**
     * 删除一个零售商信息
     *
     * @param retailerId 零售商ID
     * @return 是否删除成功
     * @throws BusinessException 业务异常
     */
    @DeleteMapping("/removeRetailerInfo")
    public ResultResponse<Boolean> removeRetailerInfo(@RequestParam @NotNull Integer retailerId) throws BusinessException {
        return ResultResponseUtils.success(retailerService.removeRetailerInfo(retailerId), "删除零售商信息成功");
    }

    /**
     * 新增一个零售商信息
     *
     * @param retailer 零售商信息对象
     * @return 是否新增成功
     * @throws BusinessException
     */
    @PostMapping("/addRetailerInfo")
    public ResultResponse<Boolean> addRetailerInfo(@RequestBody @NotNull Retailer retailer) throws BusinessException {
        return ResultResponseUtils.success(retailerService.addRetailerInfo(retailer), "新增零售商成功");
    }

}
